<?php $this->template->add_css_admin(array(
								'css/colorpicker.css',
								'css/datepicker.css',
								'css/icheck/flat/blue.css',
								'css/select2.css',
								'css/unicorn.main.css',
								'css/unicorn.grey.css',
								)); 
?>
<div class="row">
     <div class="col-12">
          <div class="widget-box">             
              <div class="widget-title">
          		<span class="icon">
          			<i class="glyphicon glyphicon-book"></i>
          		</span>
          		<h5>Quản lý Danh mục</h5>
          				<div class="buttons alert-danger">
          			<a id="add-event" href="<?php echo $this->url_edit.'0';?>" data-original-title="Thêm Danh mục" class="btn tip-top"><i class="glyphicon glyphicon-plus"></i> <span class="text">Thêm Danh mục</span></a>
          		</div>
          		</div>            

                  <div class="widget-content nopadding">
                      <table cellpadding="0" cellspacing="0" width="100%" class="table table-bordered table-striped table-hover">
                          
          	            <tbody>
                              <?php 
                                   if(isset($datas) )
                                   {
                                        foreach ($datas as $value) {
                              ?>
                              <tr id="<?php echo @$value['parent']->cat_id;?>" data-parent="1">
                                   <td><b class="catparent"><?php echo @$value['parent']->cat_name;?></b></td>
                                   <td><?php echo @$value['parent']->cat_description!=''?@$value['parent']->cat_description:'<i>chưa có mô tả</i>';?></td>
                                   <td><?php echo @$value['parent']->cat_code;?></td>
                                   <td><?php echo @$value['parent']->cat_order;?></td>
                                   <td>
                                        <a href="<?php echo $this->url_edit.@$value['parent']->cat_id;?>" class="btn btn-primary btn-mini tip-top" data-original-title="Edit">Sửa</a> 
                                        <a href="#delete" class="btn btn-danger btn-mini delete tip-top" data-toggle="modal" rel_url="<?php echo $this->url_delete.@$value['parent']->cat_id;?>" data-original-title="Delete">Xóa</a>
                                   </td>
                              </tr>
                                        <?php
                                        if(@$value['child'])
                                        foreach (@$value['child'] as $child) {
                              ?>
                              <tr id="<?php echo $child->cat_id;?>" style="display: none;">
                                   <td>
                                        <span class="catchild"> &nbsp;&nbsp;&nbsp;&nbsp;- <?php echo $child->cat_name;?></span>
                                   </td>
                                   <td><?php echo $child->cat_description!=''?$child->cat_description:'<i>chưa có mô tả</i>';?></td>
                                   <td><?php echo $child->cat_code;?></td>
                                   <td><?php echo $child->cat_order;?></td>
                                   <td>
                                        <a href="<?php echo $this->url_edit.$child->cat_id;?>" class="btn btn-primary btn-mini tip-top" data-original-title="Edit">Sửa</a> 
                                        <a href="#delete" class="btn btn-danger btn-mini delete tip-top" data-toggle="modal" rel_url="<?php echo $this->url_delete.$child->cat_id;?>" data-original-title="Delete">Xóa</a>
                                   </td>
                              </tr>     
                                        
                              <?php                                        
                                        }
                                   }
                              }
                              ?>
                              				
                              <tr style="display: none;">
                              <td colspan="6"></td>
                              </tr>
                          </tbody>
                           
                      </table>
                  </div>
          </div>
     </div>
</div>
<?php $this->template->add_js_admin(array('js/bootstrap-colorpicker.js',
										'js/bootstrap-datepicker.js',
										'js/jquery.icheck.min.js',
										'js/select2.min.js',
										'js/unicorn.form_common.js',
										'ckeditor/ckeditor.js',
										)); 
?>
<?php ob_start();?>
<script> 
$(function (){
	$('.catparent').parents('tr').attr('data-parent', "1");
	$('tr[data-parent]').click(function (){
		var un ;
		$('tr:not([data-parent])').hide();
		e  = $(this).next();
		var i=0;
		while (!$(e).attr('data-parent')){
			console.log(e);
			$(e).show('fast');
			e = $(e).next();
			i++;
			if(i > 200) break;
		}
	});
	$('tr:not([data-parent])').hide();
     $('a[data-original-title="Delete"]').click(function(){
          if(confirm("Are you sure?")){
              $.post( $(this).attr('rel_url'), function(resp) {});
          }
          $(this).closest('tr').replaceWith('');
          return false;
     });
});

</script>
<style> 
[data-parent] {
	cursor: pointer;
}
</style>
<?php $this->template->add_raw_html(ob_get_clean());
